package com.leyou.item.controller;

import com.leyou.item.pojo.dto.SpecGroupDTO;
import com.leyou.item.service.GoodsService;
import com.leyou.item.service.SpecGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//spec/groups/of/category/?id=5
@RestController
@RequestMapping("/spec")
public class SpecGroupController {

    @Autowired
    private SpecGroupService specService;

    //根据分类id查询规格组信息
    @GetMapping("/groups/of/category/")
    public ResponseEntity<List<SpecGroupDTO>> queryGroupByCategory(@RequestParam("id")Long categoryId){
        return ResponseEntity.ok(specService.queryGroupByCategory(categoryId));
    }

    //新增参数组
    @PostMapping("/group")
    public ResponseEntity<Void> addParamGroup(@RequestBody SpecGroupDTO specGroupDTO){
        specService.addParamGroup(specGroupDTO);
        return ResponseEntity.status(HttpStatus.CREATED).build();
    }


    /**
     * 根据categoryId 查询规格参数组，及组内参数
     * @param categoryId 商品分类id
     * @return 规格组及组内参数
     */
    @GetMapping("/of/category")
    public ResponseEntity<List<SpecGroupDTO>> querySpecsByCid(@RequestParam("id") Long categoryId){
        return ResponseEntity.ok().body(specService.querySpecsByCid(categoryId));
    }
}
